<%@ page language="java" contentType="text/xml; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="java.util.List"%>
<%@page import="br.com.rapidrest.demo.domain.PhoneBook"%>
<jsp:useBean id="bean" scope="request" class="br.com.rapidrest.demo.web.engine.Home" /> 
<engine xmlns:hl="http://www.holyavenger.org/holyavenger/1.0">
	<action id="content">
		<h1><%=bean.getMessages().get("title")%></h1>
		<h2><%=bean.getMessages().get("welcome")%></h2>
		
		<%
		List<PhoneBook> phonebooks = bean.getPhoneBooks();
		%>
		
		<h3><%=bean.getMessages().get("registeredPhoneBooks")%></h3>
		<table title="<%=bean.getMessages().get("registeredPhoneBooks")%>">
			<thead>
				<tr>
					<th><%=bean.getMessages().get("name")%></th>
					<th><%=bean.getMessages().get("entries")%></th>
					<th><%=bean.getMessages().get("actions")%></th>
				</tr>
			</thead>
			<tbody>
				<%
				if (phonebooks.isEmpty()) {
				%>
				<tr>
					<td colspan="3"><%=bean.getMessages().get("noRegisteredPhoneBooks")%></td>
				</tr>
				<%
				} else {
					for (PhoneBook phoneBook : phonebooks) {
				%>
				<tr>
					<td><%=phoneBook.getName()%></td>
					<td><%=phoneBook.getEntries().size()%></td>
					<td>
						<a href="#engine/phonebook/ViewPhoneBook/<%=phoneBook.getId()%>" title="<%=bean.getMessages().get("view")%>">
							<%=bean.getMessages().get("view")%>
						</a>
						<a href="#engine/phonebook/EditPhoneBook/<%=phoneBook.getId()%>" title="<%=bean.getMessages().get("edit")%>">
							<%=bean.getMessages().get("edit")%>
						</a>
						<a title="<%=bean.getMessages().get("remove")%>" href="#engine/Home"
							onclick="if (window.confirm('<%=bean.getMessages().get("confirmRemovePhoneBook")%>')) {$HL('engine/Home.removePhoneBook/<%=phoneBook.getId()%>')}; return false;">
							<%=bean.getMessages().get("remove")%>
						</a>
					</td>
				</tr>
				<%
					}
				}
				%>
			</tbody>
		</table>
		
		<a href="#engine/phonebook/NewPhoneBook" title="<%=bean.getMessages().get("createPhoneBook")%>">
			<%=bean.getMessages().get("createPhoneBook")%>
		</a>
	</action>
</engine>